<?php
include('../../__global.php');
include(SERVER_ROOT_PATH.'/include/config/ml_catelog.php');

class aj_scrolltag2 extends ml_controller
{
    private $order;
    private $tgid;
    private $tgid2;
    private $block;
    private $check_rid=0;
    
    public function initParam()
    {
        $this->order = $this->input('order','G') == 'new' ? 'new' : 'hot';
        $this->tgid = $this->input('tag','G');
        $this->tgid2 = $this->input('tag2','G');
        $page = (int)$this->input('page' , 'G' , 1);
        $block = (int)$this->input('segment' , 'G' , 2) == 2 ? 1 : 2;
        $this->tj_rid=$this->input('tj_rid','g');
        
        $page = $page < 1 ? 1 : $page;
        $page = $page > 30 ? 1 : $page;
        $this->block = ($page-1)*3 + $block;
        define('ML_SHOW_GOODS_FRM', 'pb'.$this->block);
    }
    public function checkParam()
    {
        $this->check_referer();
//        $aLmTag = ml_factory::load_standard_conf('lmTag');
//        if(!isset($aLmTag[$this->tgid]))
//            $this->api_output(ML_RCODE_HACK);
        if(!empty($this->tj_rid)){
            if(ml_tool_resid::is_resid($this->tj_rid)){
                $this->check_rid=1;
            }
        }
    }
    public function main()
    {
        $dest = '';
        if(empty($this->tgid2)){
            $page_type = 'tag_'.$this->order;
            $dest = $this->tgid;
        }else{
            $page_type = 'tag2_'.$this->order;
            $dest = $this->tgid.'/'.$this->tgid2;
        }
        $oGuang = new ml_biz_pin_guang();
        $data['items'] = $oGuang->output($page_type , $this->block , $dest, $this->__visitor['uid']);
        if($this->check_rid==1){
            $html=$this->getPinData();
            if($html != false){
                array_unshift($data['items'],$html);
                array_pop($data['items']);
            }
        }
        foreach ($data['items'] as $value) {
            $str.=$value;
        }
        $data['items']=$str;
        $data['lastSegment'] = $this->block == $oGuang->get_total_block()-1 ? true : false;
        
        
        $this->api_output(ML_RCODE_SUCC , $data);
    }
    public function getPinData(){
        $oContent=new ml_model_dbContent();
        $rs=$oContent->get_by_rid($this->tj_rid);
        if($rs){
            $conData=$oContent->get_data();
            if(isset($conData['uid'])){
                $oPinCon=new ml_biz_pin_content();
                $data=$oPinCon->output($conData['uid'],array($conData),false);
                return $data[0];
            }
        }
        return false;
    }
    
}
new aj_scrolltag2();